| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import * as sinon from 'sinon'; |
||
| 8 | describe('utils', () => { |
||
| 9 | describe('stateFlagTimeout', () => { |
||
| 10 | it('sets state and initializes timeout with provided delay', () => { |
||
| 11 | const setTimeout = sinon.fake((callback) => callback()); |
||
| 12 | const setState = sinon.spy(); |
||
| 13 | const stateFlagTimeout = stateFlagTimeoutFactory(setTimeout); |
||
| 14 | const delay = 5000; |
||
| 15 | const expectedSetStateCalls = 2; |
||
| 16 | |||
| 17 | stateFlagTimeout(setState, 'foo', false, delay); |
||
| 18 | |||
| 19 | expect(setState.callCount).toEqual(expectedSetStateCalls); |
||
| 20 | expect(setState.getCall(0).args).toEqual([{ foo: false }]); |
||
| 21 | expect(setState.getCall(1).args).toEqual([{ foo: true }]); |
||
| 22 | expect(setTimeout.callCount).toEqual(1); |
||
| 23 | expect(setTimeout.getCall(0).args[1]).toEqual(delay); |
||
| 24 | }); |
||
| 25 | }); |
||
| 26 | |||
| 27 | describe('determineOrderDir', () => { |
||
| 28 | it('returns ASC when current order field and selected field are different', () => { |
||
| 29 | expect(determineOrderDir('foo', 'bar')).toEqual('ASC'); |
||
| 30 | expect(determineOrderDir('bar', 'foo')).toEqual('ASC'); |
||
| 31 | }); |
||
| 32 | |||
| 33 | it('returns ASC when no current order dir is provided', () => { |
||
| 34 | expect(determineOrderDir('foo', 'foo')).toEqual('ASC'); |
||
| 35 | expect(determineOrderDir('bar', 'bar')).toEqual('ASC'); |
||
| 36 | }); |
||
| 37 | |||
| 38 | it('returns DESC when current order field and selected field are equal and current order dir is ASC', () => { |
||
| 39 | expect(determineOrderDir('foo', 'foo', 'ASC')).toEqual('DESC'); |
||
| 40 | expect(determineOrderDir('bar', 'bar', 'ASC')).toEqual('DESC'); |
||
| 41 | }); |
||
| 42 | |||
| 43 | it('returns undefined when current order field and selected field are equal and current order dir is DESC', () => { |
||
| 44 | expect(determineOrderDir('foo', 'foo', 'DESC')).toBeUndefined(); |
||
| 45 | expect(determineOrderDir('bar', 'bar', 'DESC')).toBeUndefined(); |
||
| 46 | }); |
||
| 47 | }); |
||
| 48 | |||
| 49 | describe('fixLeafletIcons', () => { |
||
| 50 | it('updates icons used by leaflet', () => { |
||
| 51 | fixLeafletIcons(); |
||
| 52 | |||
| 53 | const { iconRetinaUrl, iconUrl, shadowUrl } = L.Icon.Default.prototype.options; |
||
| 54 | |||
| 55 | expect(iconRetinaUrl).toEqual(marker2x); |
||
| 56 | expect(iconUrl).toEqual(marker); |
||
| 57 | expect(shadowUrl).toEqual(markerShadow); |
||
| 58 | }); |
||
| 59 | }); |
||
| 60 | }); |
||
| 61 |